﻿/*
Copyright 2010 Danny Tuppeny
http://wavenotifier.dantup.com/

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.IO;
using System.Windows.Forms;

namespace GoogleWaveNotifier
{
	static class Log
	{
		static string errorLogFile;

		static Log()
		{
			// Work out the path for the log file
			errorLogFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ErrorLog.txt");
		}

		/// <summary>
		/// Logs an error to the log file
		/// </summary>
		/// <param name="ex"></param>
		public static void Error(Exception ex)
		{
			try
			{
				File.AppendAllText(errorLogFile, ex.ToString() + "\r\n\r\n");
			}
			catch (Exception logEx)
			{
				MessageBox.Show("Unable to write to an error log. Below is the exception writing to the log file.\r\n\r\n" + logEx.ToString(), "Unable to write to Error Log!");
				MessageBox.Show("Here is the original error that could not be written to the log file.\r\n\r\n" + ex.ToString(), "Original Error");
			}
		}
	}
}
